<?php
require_once ($INCLUDE_PATH . "./include/WebService2Db.php");
class PostModel {
    public function selecturl() {
        $DB=new DB_MYSQL;
        $sql="SELECT url   FROM `".PRE."_domain`";
        $query = $DB->fetch_array($sql,DB);
        return $query;
    }
    public function selectitem() {

        $DB=new DB_MYSQL;
        $sql="SELECT *   FROM `".PRE."_project` where `state` = '2'";
        $query = $DB->fetch_array($sql,DB);
        return $query;
    }

    public function selectemail($pid,$sum,$sendtype) {
        $DB=new DB_MYSQL;


        $sql="SELECT *  FROM `".PRE."_send_email` where sendtype  LIKE '%".$sendtype."%' and state = '0' and pid ='".$pid."' LIMIT 0,".$sum;
   
        $query = $DB->fetch_array($sql,DB);
        self::updateSend_time($query);
        return $query;
    }
    public function countemail($pid) {
        $DB=new DB_MYSQL;
        $table =PRE."_send_email";
        $where = "pid =".$pid;
        $sum=$DB->count_records($table,"id",$where,DB);
        return $sum;
    }
    public function selecttem($pid) {
        $DB=new DB_MYSQL;
        $sql="SELECT *  FROM `".PRE."_email_templet` where  pid =".$pid;
        $query = $DB->fetch_array($sql,DB);
        return $query;
    }
    public function checkkey($key) {
        $DB=new DB_MYSQL;
        $sql="SELECT *  FROM `".PRE."_login_info` where l_key = '".$key."'";
        $query = $DB->fetch_array($sql,DB);
        return $query;

    }
    public function updateSend_time($mails) {
        $send_time = date("Y-m-d H:i:s");
        foreach ($mails as $key => $mail) {
            $DB=new DB_MYSQL;
            $sql = "update ".PRE."_send_email set send_time = UNIX_TIMESTAMP('".$send_time."'),state = '1' where id = ".$mail['id'];
            $query = $DB->update($sql, DB);
        }
    }
}
?>
